<template>
  <el-card class="box-card" style="height: 700px;text-align: left;overflow: scroll">
    <div slot="header" class="clearfix">
      <span>添加新诊断</span>
    </div>
    <template>
      <a style="color: gray">请选择类型：</a>
      <el-radio v-model="type" label="basic">诊断</el-radio>
      <el-radio v-model="type" label="checked">鉴别诊断</el-radio>
    </template>
    <br>
    <template>
      <a style="color: gray">请选择病证：</a>
      <el-select v-model="name" placeholder="请选择">
        <el-option
          v-for="item in AnalysisData[type]"
          :key="item.name"
          :label="item.name"
          :value="item.name"
          :disabled="item.selected">
        </el-option>
      </el-select>
    </template>
    <br>
    <template>
      <a style="color: gray">请选择支持依据：</a>
      <analysis-selector :items="$store.getters.fullyQuestions" @changed="getRes"></analysis-selector>
    </template>
    <br>
    <template v-if="type === 'checked'">
      <a style="color: gray">请选择排除依据：</a>
      <analysis-selector :items="$store.getters.fullyQuestions" @changed="getRes2"></analysis-selector>
    </template>
    <br>
    <el-button type="primary" @click="submitAnalysis">添加诊断</el-button>

  </el-card>

</template>

<script>
import data from "../../../data";
import AnalysisSelector from "./AnalysisSelector";
export default {
  name: "AnalysisAdd",
  components: {AnalysisSelector},
  data(){
    return{
      type: 'basic',
      name: '',
      AnalysisData: data.data().analysis,
      value: [],//支持依据
      value2:[]//不支持依据
    }
  },
  methods: {
    getRes(data){
      this.value = data
    },
    getRes2(data){
      this.value2 = data
    },
    submitAnalysis(){
      if(this.name === ''){
        this.$notify.error({
        title: '错误',
        message: '您没有选择病证'
      });
      return
      }
      let paramMap = {type:'',dataAgreement:[],dataDisagreement:[],index:0,name:''}
      if(this.type==='basic'){
        if(this.value.length === 0){
          this.$notify.error({
            title: '错误',
            message: '您没有选择支持依据'
          });
          return
        }
        paramMap.type = this.type
        paramMap.name = this.name
        paramMap.dataAgreement = this.value
        data.data().analysis[this.type].forEach(((data,indexx)=>{
          if(data.name === this.name){
            paramMap.index = indexx
          }
        }))
      }
      else if(this.type === 'checked'){
        if(this.value.length === 0 || this.value2.length === 0){
          this.$notify.error({
            title: '错误',
            message: '您没有选择支持依据或者不支持依据'
          });
          return
        }
        paramMap.type = this.type
        paramMap.name = this.name
        paramMap.dataAgreement = this.value
        paramMap.dataDisagreement = this.value2
        data.data().analysis[this.type].forEach(((data,indexx)=>{
          if(data.name === this.name){
            paramMap.index = indexx
          }
        }))
      }
      //返回给VUEX Store的三个变量，封装在一个对象里
      this.$store.commit('diagnosisPush',paramMap)

      this.AnalysisData[this.type][paramMap.index].selected = true

    }
  },
  watch:{
    type: function () {
      this.name = ''
    }
  }
}
</script>

<style scoped>

</style>
